﻿// Decompiled by AS3 Sorcerer 6.78
// www.buraks.com/as3sorcerer

//com.wdcgame.tile.model.ObjectVO

package com.game.tile.model
{
    import base.BaseVO;
    
    import com.dusk.util.StringUtil;
    
    import com.game.engine.phys.Vector2D;
    import flash.utils.Dictionary;
    import flash.geom.Rectangle;

    public class ObjectVO extends BaseVO
    {

        public var polygonPoints:Vector.<Vector2D>;
        public var name:String;
        public var type:String;
        public var x:int;
        public var y:int;
        public var width:int;
        public var height:int;
        public var rotation:Number = 0;
        public var properties:Dictionary;
        public var ellipse:Boolean;
        public var polygon:Boolean;
        public var createAtInit:Boolean;
        public var layer:String;


        override public function buildFromXMLAttr(_arg_1:XML):void
        {
            var _local_7:* = null;
            var _local_4:* = null;
            var _local_5:* = null;
            var _local_6:int;
            var _local_3:* = null;
            var _local_2:* = null;
            super.buildFromXMLAttr(_arg_1);
            properties = new Dictionary();
            for each (var _local_8:XML in _arg_1.properties.property)
            {
                properties[String(_local_8.@name)] = String(_local_8.@value);
                _local_7 = _local_8.@type;
                if (StringUtil.trim(_local_7) != "")
                {
                    if (_local_7 == "float")
                    {
                        properties[String(_local_8.@name)] = Number(_local_8.@value);
                    }
                    else
                    {
                        if (_local_7 == "int")
                        {
                            properties[String(_local_8.@name)] = int(_local_8.@value);
                        }
                        else
                        {
                            if (_local_7 == "bool")
                            {
                                properties[String(_local_8.@name)] = false;
                                if (_local_8.@value == "true")
                                {
                                    properties[String(_local_8.@name)] = true;
                                }
                            }
                        }
                    }
                }
                if (_local_8.@type != "")
                {
                }
            }
            ellipse = _arg_1.hasOwnProperty("ellipse");
            polygon = _arg_1.hasOwnProperty("polygon");
            if (polygon)
            {
                _local_4 = _arg_1.polygon.@points;
                _local_5 = _local_4.split(" ");
                this.polygonPoints = new Vector.<Vector2D>();
                _local_6 = 0;
                while (_local_6 < _local_5.length)
                {
                    _local_3 = _local_5[_local_6].split(",");
                    _local_2 = new Vector2D(_local_3[0], _local_3[1]);
                    polygonPoints.push(_local_2);
                    _local_6++;
                }
            }
            if (this.properties.hasOwnProperty("createAtInit"))
            {
                this.createAtInit = this.properties.createAtInit;
            }
            else
            {
                this.createAtInit = true;
            }
            this.layer = this.properties["layer"];
        }

        public function getBodyRec():Rectangle
        {
            return (new Rectangle((x + (width / 2)), (this.y + (height / 2)), this.width, this.height));
        }

        public function getCenter():Vector2D
        {
            var _local_6:Number;
            var _local_3:Number;
            var _local_7:Number;
            var _local_4:Number;
            var _local_8:int;
            var _local_1:* = null;
            var _local_2:Number;
            var _local_5:Number;
            if (polygon)
            {
                _local_6 = 99999;
                _local_3 = -99999;
                _local_7 = 99999;
                _local_4 = -99999;
                _local_8 = 0;
                while (_local_8 < polygonPoints.length)
                {
                    _local_1 = polygonPoints[_local_8];
                    if (_local_1.x < _local_6)
                    {
                        _local_6 = _local_1.x;
                    }
                    if (_local_1.x > _local_3)
                    {
                        _local_3 = _local_1.x;
                    }
                    if (_local_1.y < _local_7)
                    {
                        _local_7 = _local_1.y;
                    }
                    if (_local_1.y > _local_4)
                    {
                        _local_4 = _local_1.y;
                    }
                    _local_8++;
                }
                _local_2 = (_local_3 - _local_6);
                _local_5 = (_local_4 - _local_7);
            }
            return (new Vector2D((x + (width / 2)), (this.y + (height / 2))));
        }


    }
}//package com.wdcgame.tile.model

